/** 
 * @author (Gruppe G) 
 * @version (04/18/2012)
 */

package ControlLayer;
import java.util.ArrayList;
import ModelLayer.*;

public class LendCtr
{

    private LendCollection lendCollection;
    private DVDCtr dvdCtr;
    private AddressCtr addressCtr;
    
    /**
     * Constructor for objects of class LendCtr
     */
    public LendCtr()
    {
        lendCollection = LendCollection.getInstance();
        dvdCtr = new DVDCtr();
        addressCtr = new AddressCtr();
    }
    
    /**
     * Creating a lend with personal and movie besides the lend information.
     * 
     * @param date sets the date for the lend
     * @param period sets the period for the lend
     * @param status sets the status for the lend
     */
    public void createLend(DVD dvdObj, Person personObj, String date, String period, String status)
    {
        Lend LendObj = new Lend(dvdObj, personObj, date, period, status);
        lendCollection.addLend(LendObj);
    }
    
    /**
     * Finds movie via its title in array trough the dvd controller.
     * 
     * @param DVDtitle movie title to be used in search
     */
    public DVD findDVD(String DVDtitle)
    {
        return dvdCtr.findDVD(DVDtitle);
    }
    
    /**
     * Finds person via phonenumber in array trough the addressbook controller.
     * 
     * @param personPhone persons phonenumber to be used in search
     */
    public Person findPerson(String personPhone)
    {
        return addressCtr.getPerson(personPhone);
    }
    
    /**
     * Finds all lends that belongs to a specefic person via phonenumber trough the lendcollection model
     * 
     * @param personPhone persons phonenumber to be used in search
     */
    public ArrayList<Lend> findAllLends(String personPhone)
    {
        return lendCollection.findAllLends(personPhone);
    }
    
    /**
     * Replaces the status of a lend to the specified string.
     * 
     * @param status the string to replace the current one.
     */
    public void editLendStatus(Lend lendObj, String status)
    {
        lendObj.setStatus(status);
    }
    
    /**
     * Returning a lend via persons phonenumber and the movie title.
     * 
     * @param personPhone the persons phonenumber to be used when returning a lend
     * @param title the movie title to be used when returning a lend
     */
    public Lend ReturnLend(String personPhone, String title)
    {
        return lendCollection.ReturnLend(personPhone, title);
    }
}